package com.yanggu.scala.chapater10

import scala.collection.mutable.ArrayBuffer

//ArrayBuffer.toArray
//Array.toBuffer
object Array22ArrayBuffer {

  def main(args: Array[String]): Unit = {
    //初始化可变数组
    val arrBuffer = ArrayBuffer[Int](1, 2, 3)
    println(arrBuffer.mkString(", "))

    //将可变数组转成不可变数组
    val array = arrBuffer.toArray
    println(array.mkString(", "))
    //修改值
    array(0) = 100
    println(array.mkString(", "))
    //这里可以看到修改array中的值原有arrayBuffer中的值并没有发生修改。
    //这里说明scala的array和ArrayBuffer是深拷贝
    println(arrBuffer.mkString(", "))

    val arr01 = Array[Int](1, 2, 3)
    val buffer = arr01.toBuffer
    println(buffer.mkString(", "))
  }

}
